package cn.edu.csust.cvs.management.service.impl;

import cn.edu.csust.cvs.management.common.ApiResult;
import cn.edu.csust.cvs.management.controller.request.UserLoginRequest;
import cn.edu.csust.cvs.management.repository.UserRepository;
import cn.edu.csust.cvs.management.repository.entity.UserEntity;
import cn.edu.csust.cvs.management.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
/**
 * @Auther: snail
 * @Date: 2021/3/1 00:30
 * @Description: 系统登录
 */
@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    UserRepository userRepository;

    @Override
    public ApiResult<Boolean> login(UserLoginRequest request) {
        UserEntity user = new UserEntity();
        user.setUsername(request.getUsernmae());
        user.setPassword(request.getPassword());
        boolean isOk = userRepository.exists(Example.of(user));
        return ApiResult.ok(isOk);
    }
}
